home *** CD-ROM | disk | FTP | other *** search
- /*
- * day.c
- *
- * Main file for macintosh day client. to run with my modified dayd daemon.
- *
- * Mike Trent 8/94
- *
- */
-
-
-
- /* Main Mac Includes */
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <SegLoad.h>
-
- /* Additional Mac Includes */
- #include <MacTCPCommonTypes.h> //for ip.h
-
- /* Ansi Includes */
- #include <stdio.h>
-
- /* Additional Includes */
- #define MAIN
- #include "globals.h"
- #include "ip.h"
-
- void InitToolBox(void);
- void get_data(char *str);
-
- main()
- {
- WindowPtr w;
- Rect windRect;
- char s[100];
-
- InitToolBox();
-
- SetRect(&windRect, 40,40,300,150);
- if ( (w = NewWindow (nil, &windRect, "\pDate", true, documentProc, (WindowPtr) -1, false, 0)) == nil) {
- SysBeep(3);
- return;
- }
- SetPort(w);
-
- MoveTo(10,15);
- DrawString("\pDay Client: port 1026");
-
- get_data(s);
-
- MoveTo(10,30);
- DrawString((ConstStr255Param)s);
-
- while (!Button());
-
- CloseWindow(w);
- }
-
-
- void InitToolBox(void)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- if (InitMacTCP() != noErr) {
- SysBeep(3);
- ExitToShell();
- }
- }
-
- void get_data(char *str)
- {
- int s, err, n= 1, tot = 0;
- struct sockaddr_in sa;
-
- s = socket(IPPROTO_TCP);
- if (s < 0) {
- sprintf(str, (const char *)"\psocket() e%d, m%d", gErrno, gMacErrno);
- return;
- }
-
- sa.sin_port = 1026;
- sa.sin_addr = GetHostByName("144.89.40.6");
- //sa.sin_addr = 0x90592866;
- if (sa.sin_addr == 0) {
- sprintf(str, (const char *)"\pGetHostByName() e%d, m%d", gErrno, gMacErrno);
- return;
- }
-
- if ((err = connect(s,&sa)) != noErr) {
- sprintf(str, (const char *)"\pconnect error");
- return;
- }
-
- while ((n=mac_read(s, str, 100)) > 0) {
- str[n] = '\0';
- tot += n; //keep a running total of length of bytes received.
- }
-
- for (n=tot-1; n >=0; n--) {
- str[n+1] = str[n];
- }
- str[0] = tot-1;
-
- if (mac_close(s)) {
- //sprintf(str, (const char *)"\pclose error() e%d, m%d", gErrno, gMacErrno);
- return;
- }
- }